<template>
  <div>
    <div class="contact" :class="hide?'out':'in'">
      <image
        @tap="showContact" :style="hide?'z-index:100':'z-index:99'"
        class="contact-img"
        src="/static/images/contact.png"
        mode="aspectFit"
        lazy-load="false">
      </image>
      <button class="contact-btn" open-type="contact" @contact="handleContact" :style="hide?'z-index:99':'z-index:100'">客服</button>
    </div>
  </div>
</template>

<script>
export default {
  name: "Contact",
  data () {
    return {
      hide: true,
      scrollTop: 0, // 滚动位置
      last: 0, // 上次时间
    }
  },
  methods: {
    // 显示客服按钮
    showContact () {
      this.hide = false
      setTimeout(() => {
        this.hide = true
      }, 5000)
    },
    handleContact(e) {
      // console.log(e.path)
      // console.log(e.query)
    },

  },
  onPageScroll (e) {
    let now = new Date().getTime()
    if (now - this.last > 200 || !this.last) {
      console.log('--')
      // 触发函数，保存当前时间
      this.last = now
      // 滚动回弹情况
      if (e.scrollTop <= 0) {
        e.scrollTop = 0;
      } else if (e.scrollTop > wx.getSystemInfoSync().windowHeight) {
        e.scrollTop = wx.getSystemInfoSync().windowHeight
      }
      // 上下滚动判断
      if (e.scrollTop > this.scrollTop || e.scrollTop == wx.getSystemInfoSync().windowHeight) {
        this.hide = true
      } else {
        this.hide = false
      }
      // 记录当前滚动位置
      this.scrollTop = e.scrollTop
    }
  },

}
</script>

<style lang="scss" scoped>
.contact {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  bottom: 50rpx;
  right: 50rpx;
  width: 80rpx;
  height: 80rpx;
  background-color: #fff;
  border-radius: 50%;
  box-shadow: 0 0 20rpx #888;
  .iconfont {
    position: absolute;
    z-index: 100;
    font-size: 70rpx;
    color: #888;
    text-align: center;
  }
  .contact-btn {
    position: absolute;
    z-index: 99;
    width: 100%;
    height: 100%;
    opacity: 0;
  }
}
.out {
  transition: transform .5s;
  transform: translateX(80rpx);
}
.in {
  transition: transform .5s;
  transform: translateX(0);
}
</style>
